package com.iflytek.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class CodeGenerator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/sign_in?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
        String username = "flytech";
        String password = "flytech";

        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("周超") // 设置作者
                            .outputDir(System.getProperty("user.dir") + "/src/main/java") // 指定输出目录
                            .disableOpenDir(); // 禁止打开输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.iflytech") // 设置父包名
                            .entity("entity")
                            .mapper("mapper")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,
                                    System.getProperty("user.dir") + "/src/main/resources/mapper")); // 设置mapper XML生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("train_class", "student", "sign_in_record") // 设置需要生成的表名
                            .entityBuilder() // 实体类策略配置
                            .enableLombok() // 开启lombok
                            .enableTableFieldAnnotation() // 生成字段注解
                            .enableFileOverride()  //覆盖已有文件
                            .mapperBuilder(); // mapper策略配置
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板
                .execute();
    }
}